package com.example.demo.mapper;

import com.example.demo.model.Goods;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.Mapping;

import java.util.List;

@Mapper
public interface GoodsMapper {
    @Insert("INSERT INTO goods (number, name, price, description, place) " +
            "VALUES (#{number}, #{name}, #{price}, #{description}, #{place})")
    void add(Goods goods);

    @Delete("DELETE FROM goods WHERE number = #{number}")
    void delete(int number);

    @Update("UPDATE goods SET name=#{goods.name}, price=#{goods.price}, description=#{goods.description}, place=#{goods.place} WHERE number=#{targetNumber}")
    void update(@Param("goods") Goods goods, @Param("targetNumber") int targetnumber);

    @Select("SELECT * FROM goods")
    List<Goods> list();

    @Select("SELECT * FROM goods WHERE number= #{number}")
    List<Goods> select(int number);
}
